package com.peace.hospital.opdept.mapper.outpatientdept;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.peace.hospital.entity.outpatientdept.Patientinformation;
import com.peace.hospital.entity.outpatientdept.dto.RegisteredEnquiryDto;
import org.apache.ibatis.annotations.*;

import java.sql.Date;
import java.util.List;

/**
 * <p>
 * 挂号信息表 Mapper 接口
 * </p>
 *
 * @author 谢晓峰
 * @since 2019-11-11
 */
@Mapper
public interface PatientinformationMapper extends BaseMapper<Patientinformation> {

    /**添加挂号信息*/
    @Insert("insert into outpatientDepartment.patientinformation(staid,pid,patrdate,pstate,patdbsource) values(#{staid},#{pid},#{patrdate},1,'outpatientDepartment')")
    int addPatientinformation(Patientinformation patientinformation);

    /**按照病人id查询挂号信息*/
    @Select("select * from outpatientDepartment.patientinformation where pid=#{pid} and pstate= 1 ")
    Patientinformation selectPatientinformationByPid(Integer pid);

    /**查询是否有该挂号信息*/
    @Select("select * from outpatientDepartment.patientinformation where pid=#{pid} and patrdate = now() and pstate= 1 ")
    Patientinformation selectPatientinformationOne(Patientinformation patientinformation);

    /**修改挂号状态0-为退号状态*/
    @Update("update outpatientDepartment.patientinformation SET pstate= 0 where patid=#{patid}")
    int updatePatientinformationById(Integer patid);

    /**按照日期查询挂号信息*/
    @Select("select pat.patid,pat.parchargeitemid,p.pname,s.staname,d.deptype from outpatientDepartment.patientinformation pat " +
            "inner join hospital_public.people p on pat.pid = p.pid " +
            "inner join hospital_public.staffinfo s on pat.staid=s.staid " +
            "inner join hospital_public.department d on d.depid=s.depid " +
            "where patrdate=#{patrdate} and pstate = 1")
    @Results({
            @Result(property = "patientinformation.patid",column = "patid"),
            @Result(property = "patientinformation.parchargeitemid",column = "parchargeitemid"),
            @Result(property = "people.pname",column = "pname"),
            @Result(property = "staffinfo.staname",column = "staname"),
            @Result(property = "department.deptype",column = "deptype")
    })
    List<RegisteredEnquiryDto> selectPeopleRegisterByDate(Patientinformation patientinformation);
}
